#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[100005],c[100005],t,ans;
void dfs(ll b){
    if(b==n+1){
        ll A=0;
        ll B=0;
        ll sum=0;
        for(int i=1;i<=n;i++){
            if(c[i]==0){
                if(a[i]==A)sum+=A;
                A=a[i];
            }
            else {
                if(a[i]==B)sum+=B;
                B=a[i];
            }
        }
        ans=max(ans,sum);
        return ;
    }
    c[b]=0;
    dfs(b+1);
    c[b]=1;
    dfs(b+1);
}
int main () {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n;
        ans=0;
        for(int i=1;i<=n;i++){
            c[i]=0;
            cin>>a[i];
        }
        dfs(1);
        cout<<ans<<endl;
    }
    return 0;
}